fix(tui): preserve current selection across list updates - #39774
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Keep a dialog's blue selection attached to its current item when asynchronously loaded options are inserted or reordered.
This fixes the session picker showing the current-session dot on one row while Enter would select a different blue-highlighted row.
Before / After
Before: The session picker rendered cached sessions and selected the current session by numeric index. When the server response replaced that list with more sessions or a different order, the index stayed fixed and silently pointed at another session. The dot still followed the current session ID, so the dot and blue selection diverged.
After: A dialog with a
currentvalue reconciles selection by option value across list updates. Reordering the options moves the selected index with the same session, keeping the current marker, blue highlight, and Enter behavior aligned.How
packages/tui/src/ui/dialog-select.tsxtreatscurrentselections as value-preserving during option reconciliation and post-layout scrolling.packages/tui/test/cli/tui/dialog-select.test.tsxreplaces[first, current, third]with[current, third, first]and verifies Enter still submitscurrent.Scope
Dialogs without a
currentitem retain their existing index-based reconciliation behavior. Filtering and explicitpreserveSelectionbehavior are unchanged.Testing
bun run typecheckfrompackages/tuibun run testfrompackages/tui: 574 passed, 5 skippedDemo
Simulated sessions driven through the real V2 TUI in a PTY using the Drive startup fix in anomalyco/opencode-drive#50. The blue selection first moves independently while Golf remains current; after switching to Charlie and reopening, the dot and selection are aligned on Charlie.
session-picker-selection-fix.mp4
Flow